package com.fand.manager.model.user;

import java.util.Objects;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.fand.common.annotation.DataField;
import com.fand.common.enums.ConditionOnField;
import com.fand.common.model.BaseDTO;
import com.fand.common.util.JsonUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * Author: zhangjiabin
 * Email: javaboyok@163.com
 * CreateDate: 2021/6/3
 * Version: 1.0
 */
@Data
public class SysUserSearchDTO extends BaseDTO {

    @ApiModelProperty(value = "用户名")
    @DataField(tableFiled = "user_name",condition = ConditionOnField.LIKE_RIGHT)
    private String userName;

    @ApiModelProperty(value = "用户编码")
    @DataField(tableFiled = "user_code",condition = ConditionOnField.LIKE_RIGHT)
    private String userCode;

    @ApiModelProperty(value = "邮箱")
    @DataField(tableFiled = "email",condition = ConditionOnField.LIKE_RIGHT)
    private String email;

    @ApiModelProperty(value = "手机号")
    @DataField(tableFiled = "mobile",condition = ConditionOnField.LIKE_RIGHT)
    private String mobile;

    public SysUserSearchDTO builder() {
        if (Objects.isNull(getSearchParams())) {
            return this;
        } else {
            SysUserSearchDTO sysUserSearchDTO = JsonUtils.jsonToPojo(JsonUtils.objectToJson(JsonUtils.jsonToPojo(getSearchParams(), SysUserSearchDTO.class)), SysUserSearchDTO.class);
            CopyOptions copyOptions = CopyOptions.create();
            copyOptions.setIgnoreNullValue(true);
            BeanUtil.copyProperties(sysUserSearchDTO,this, copyOptions);
            return this;
        }
    }
}
